package com.xywh.wanandroid.util

import android.widget.TextView

object TimeUtils {

    fun liveDescCountTime(
        ms: Long,
        tvDays: TextView,
        tvHour: TextView,
        tvMinutes: TextView,
        tvSeconds: TextView
    ) {
        val totalSeconds = ms / 1000
        val seconds = totalSeconds % 60
        val minutes = totalSeconds / 60 % 60
        val hours = totalSeconds / 60 / 60 % 24
        val days = totalSeconds / 60 / 60 / 24
        var dayStr = ""
        if (days > 0) {
            dayStr += if (days > 9) {
                days.toString() + ""
            } else if (days > 0) {
                "0$days"
            } else {
                "00"
            }
        } else {
            dayStr = "00"
        }
        tvDays.text = dayStr
        var hourStr = ""
        if (hours > 0) {
            hourStr += if (hours > 9) {
                hours.toString() + ""
            } else if (hours > 0) {
                "0$hours"
            } else {
                "00"
            }
        } else {
            hourStr = "00"
        }
        tvHour.text = hourStr
        var minutesStr = ""
        minutesStr += if (minutes > 9) {
            minutes.toString() + ""
        } else if (minutes > 0) {
            "0$minutes"
        } else {
            "00"
        }
        tvMinutes.text = minutesStr
        var secondStr = ""
        if (seconds > 9) {
            secondStr += seconds
        } else if (seconds > 0) {
            secondStr += "0$seconds"
        } else {
            secondStr += "00"
        }
        tvSeconds.text = secondStr
    }
}